<template>
	<u-picker :show="deviceTypeShow" :columns="deviceTypeList" keyName="label" 
	 immediateChange ="true" @confirm="confirm()" @cancel="cancel()"
		@close="close()"  @change="change()" closeOnClickOverlay="true">
	</u-picker>

</template>

<script>
	export default {
		name: "device-type",
		data() {
			return {
        index:[],
				deviceTypeShow: false,
				deviceTypeList: [
					[]
				],
			};
		},
		created() {
			this.findAllMerchantdeviceByUserId();
		},
		methods: {
			init(merchantStoreId, deviceTypeShow) {
				if (merchantStoreId) {
					this.param.merchantStoreId = merchantStoreId
					if (merchantStoreId) {
						this.findAllMerchantdeviceByUserId();
					}
				}
        // this.index=[];
        // this.index.push(1);
				if (deviceTypeShow) {
					this.deviceTypeShow = true;
				} else {
					this.deviceTypeShow = false;
				}
			},
			confirm(e) {
				this.deviceTypeShow = false;
				this.$emit('deviceTypeData', e.value[0]);
			},
			change(e){
				console.log(e);
			},
			cancel() {
				this.deviceTypeShow = false;
			},
			close() {
				this.deviceTypeShow = false;
			},


			findAllMerchantdeviceByUserId() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				this.deviceTypeList[0] = [{
					value: '-1',
					label: '不限'
				}];
				this.deviceTypeList[0].push()
				this.$api('deviceType.curr', this.param).then(res => {
					if (res.status == 0) {
						for (let d of res.data) {
							this.deviceTypeList[0].push({
								value: d.id,
								label: d.deviceTypeName
							})
						}
						uni.hideLoading();
					} else {
						uni.hideLoading();
						this.$helpers.toast('请求数据失败:' + res.data.msg);
					}
				});
			},
		}
	}
</script>

<style>

</style>
